package com.lenovo.srl.dil.tiltbase.position.fragment;

import android.graphics.Point;

import com.lenovo.srl.dil.tiltbase.lib.fragment.BaseFragment;

public class PositionFragment extends BaseFragment {

	public PositionFragment() {
		mCtrlMode = CtrlMode.Position;
	}

	@Override
	protected void moveDivier(float[] sensorData) {
		hideDivider();
	}

	@Override
	protected double[] calcXYOffset(float[] sensorData, Point curBallPosition) {
		double tiltMag = Math.sqrt(sensorData[1] * sensorData[1]
				+ sensorData[2] * sensorData[2]);
		double tiltAngle = Math.asin(sensorData[2] / tiltMag) * 180 / Math.PI;
		int tiltGain = getTiltGainByTiltAngle(tiltAngle);
		double dBall = tiltGain * Math.abs(tiltMag);

		double[] result = new double[2];
		result[0] = dBall * Math.sin(tiltAngle * Math.PI / 180);
		result[1] = (sensorData[1] > 0 ? -1 : 1) * dBall
				* Math.cos(tiltAngle * Math.PI / 180);
		return result;
	}

	@Override
	protected boolean moveBallX2CenterWhenUpdate() {
		return true;
	}

	@Override
	protected boolean moveBallY2CenterWhenUpdate() {
		return true;
	}

	@Override
	protected float getSensorDelta() {
		return .5f;
	}
}
